/*
 * Created on Dec 20, 2004
 *
 */
package com.softplus.carrefour.hd.bltier.admin;

import java.util.HashMap;
import java.util.List;
import java.util.Vector;

import net.sf.hibernate.HibernateException;

import com.epro.standard.frontend.lov.LOVKeyword;

import com.softplus.carrefour.CFException;
import com.softplus.carrefour.hd.bltier.db.HibernateUtil;
import com.softplus.carrefour.hd.bltier.entity.CfhdModule;
import com.softplus.carrefour.hd.bltier.util.LOVtemplate;

/**
 * @author Turbo
 * Create Date : Dec 20, 2004
 * Update By : Turbo
 * Update Date : Dec 20, 2004
 * Version : 1.0
 * 
 */
public class CFHDModuleManage implements ICFHDModuleControl, 
                                         ICFHDModuleViewer {


    /* (non-Javadoc)
     * @see com.softplus.carrefour.hd.bltier.admin.ICFHDModuleViewer#getLOVModule()
     */

    public Vector getLOVModule(LOVKeyword key) throws CFException {

        String searchValue = key.getMessage();
        Vector checkBoxs = key.getCheckBox();
        HashMap conds = key.getCondition();

        if (checkBoxs.size() == 0) { //no checkbox was checked 
            checkBoxs.addElement("0");
        }

        HashMap serachCols = new HashMap();

        serachCols.put("0", "CFHD_MODULE");
        serachCols.put("1", "CFHD_SYSTEM");

        String sql = 
            "select " + "CFHD_MODULE, CFHD_SYSTEM " + " from CFHD_MODULE " + 
            " where (1=1) and (";

        return new LOVtemplate().getLOV(sql, 
                                        new String[] { "CFHD_MODULE", "CFHD_SYSTEM" }, 
                                        searchValue, serachCols, checkBoxs, "", 
                                        "");
    }

    public Vector getListModule() throws CFException {
        List ls = null;
        try {
            ls = 
 HibernateUtil.getSession().createCriteria(CfhdModule.class).list();
        } catch (HibernateException e) {
            e.printStackTrace();
        } finally {
            HibernateUtil.closeSession();
        }

        Vector modules = new Vector();
        if ((ls != null) && (ls.size() > 0)) {
            for (int i = 0; i < ls.size(); i++) {
                modules.addElement(((CfhdModule)ls.get(i)).getCfhdModule() + 
                                   " - " + 
                                   ((CfhdModule)ls.get(i)).getCfhdSystem());
            }
        }
        return modules;
    }

    public Vector getListModuleBySystem(String system) throws CFException {
        List ls = null;
        String hql = "from CfhdModule c where c.cfhdSystem = '" + system + "'";
        try {
            ls = HibernateUtil.getSession().createQuery(hql).list();
        } catch (HibernateException e) {
            e.printStackTrace();
        } finally {
            HibernateUtil.closeSession();
        }

        Vector modules = new Vector();
        if ((ls != null) && (ls.size() > 0)) {
            for (int i = 0; i < ls.size(); i++) {
                modules.addElement(((CfhdModule)ls.get(i)).getCfhdModule() + 
                                   " - " + 
                                   ((CfhdModule)ls.get(i)).getCfhdSystem());
            }
        }
        return modules;
    }
}
